package com.wmh.baseservice.common.shiro.config;

import com.wmh.baseservice.admin.service.AdInfoService;
import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.credential.SimpleCredentialsMatcher;

import javax.annotation.Resource;

/**
 * @author xy
 * @Date: 2021-10-20 15:21
 * @describe 自定义密码比较器
 */
public class PasswordMatcher extends SimpleCredentialsMatcher {

   @Resource
    private AdInfoService adInfoService;


    @Override
    public boolean doCredentialsMatch(AuthenticationToken token, AuthenticationInfo info) {
        String password = info.getCredentials().toString();
        String[] users = info.getPrincipals().toString().split("\\.");
        String userName = users[0];
        String rawPassword = users[1];
        if (userName.contains(ShiroConfig.SHIRO_ADMIN)) {
            return password.equals(rawPassword);
        } else if (userName.contains(ShiroConfig.SHIRO_SSO)) {
            //单点登录情况下直接放行
            return true;
        }
        return false;
    }

}
